//https://leetcode.cn/problems/combination-sum-iv/submissions/562948437/

class Solution {
public:
    int combinationSum4(vector<int>& nums, int target) {
        vector<unsigned long long> dp(target + 1, 0);
        dp[0] = 1;
        // 递推方向从前面来，类似爬楼梯
        // 假设排列的最后一个元素是num，i的方案数就等于 dp[i-num]
        for (int i = 1; i <= target; i++)
            for (auto& it : nums)  {
                if (it <= i)
                    dp[i] += dp[i-it];
            }
                
        return dp[target];
    }
};